<?php
$smarty->configLoad($lang . '/rule.module.php');
$language = parse_ini_file($lang . '/breadcrumb.module.php', true);
$breadcrumb = $language['add_rule'];

$template = 'rules/add.tpl';

if (isset($_POST['add_protocol'])) {
	$main->logAction($_SESSION['id'], 'rules_add_log');
	$sql = 'INSERT INTO '.DB_CMS.'.module_rules (name) VALUES (:name)';
	$stm = $connection->prepare($sql);
	$stm->bindValue(':name', $_POST['protocol_name']);
	$stm->execute();
	$lastid = $connection->lastInsertId();
	$i = 0;

	foreach ($_POST['protocol_titel'] as $value) {
		if (!empty($_POST['protocol_titel'][$i])) {
			$sql = 'INSERT INTO '.DB_CMS.'.module_rules_points (ruleID, text, title) VALUES (:ruleID, :text, :title)';
			$qry1 = $connection->prepare($sql);
			$qry1->bindValue(':ruleID', $lastid);
			$qry1->bindValue(':text', $_POST['protocol_information'][$i]);
			$qry1->bindValue(':title', $_POST['protocol_titel'][$i]);
			$qry1->execute();
			$i++;
		}
	}
	$main->jqmodal('addet');
	echo '<meta http-equiv="refresh" content="5; URL=index.php?mod=rules&page=detail&id='.$lastid.'">';
}
?>
